package com.itttq.gshop.h5.cmpt;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class GenericGrap {
	static Map<String, Map<String, String>> cookies = new HashMap<String, Map<String, String>>();
	public static Document getDoc(String url) throws IOException {
		Document doc =Jsoup.connect(url)
				.userAgent("Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2") // 设置 User-Agent 
				.timeout(5000)           // 设置连接超时时间
				.get(); // get方式访问
		return doc;
	}
	
	public static String getJsonContent(String url) throws IOException {
		return Jsoup.connect(url).timeout(60000)
				.userAgent("Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2") // 设置 User-Agent
				.ignoreContentType(true).execute().body();
	}
	
	public static void main(String[] args) throws IOException {
		// 静默登录地址
		String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx24eb520310b782ab&secret=770fefe8f86f1627b90894b0dde2eab2&code=061SRyDd1Mkc1t0Qi5Ed1dmNDd1SRyDS&grant_type=authorization_code";
		// 先静默登录，没有code则非静默授权登录并获取用户信息绑定
		System.out.println(getJsonContent(url));
	}
	
}
